package com.jcli._自己的想法._文件流._获取路径;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 使用Java的ProcessBuilder类执行ADB命令来获取连接的Android设备上的文件列表：
 */
public class ADBFileLister01 {

    public static void main(String[] args) {
        listFilesOnDevice();
    }

    public static void listFilesOnDevice() {
        try {
            // 构建ADB命令
            String[] command = {"adb", "shell", "ls"};

            // 执行ADB命令
            ProcessBuilder processBuilder = new ProcessBuilder(command);
            Process process = processBuilder.start();

            // 读取命令输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

            // 等待命令执行完成
            int exitCode = process.waitFor();
            System.out.println("Command executed with exit code: " + exitCode);

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
